package com.horizon.service.endpoint.controller;

import com.horizon.common.exception.HorizonException;
import com.horizon.manage.endpoint.service.IEndpointService;
import com.horizon.service.endpoint.dto.EndpointOperation;
import com.horizon.service.endpoint.service.EndpointOperationService;
import lombok.AllArgsConstructor;
import org.springblade.core.secure.utils.SecureUtil;
import org.springblade.core.tool.api.R;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 终端操作控制器.
 *
 * @author zhaoshb
 * @since 2023/1/2 00:34
 */
@RestController
@AllArgsConstructor
@RequestMapping("/horizon/service/endpoint")
public class EndpointOperationController {

    private EndpointOperationService endpointOperationService;

    @GetMapping("/operations/{endpointId}")
    public R<List<EndpointOperation>> getOperations(@PathVariable Long endpointId) throws HorizonException {
        return R.data(endpointOperationService.popOperation(SecureUtil.getTenantId(), endpointId));
    }

    @PostMapping("/operations/{endpointId}")
    public R<Boolean> postOperations(@PathVariable Long endpointId, @RequestBody List<EndpointOperation> operationList) {
        return R.data(endpointOperationService.pushOperation(endpointId, operationList));
    }
}
